package com.xjc.business.controller.stu;

import com.xjc.business.entity.po.stu.AuthPo;
import com.xjc.business.entity.po.stu.MatchFacePo;
import com.xjc.business.entity.vo.stu.AllSchoolVo;
import com.xjc.business.entity.vo.stu.AuthVo;
import com.xjc.business.service.SchoolsService;
import com.xjc.business.service.WxAuthenticatedIdentityApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 徐锦程
 * 时间:2025-02-03 14:26
 */
@RestController
@RequestMapping("/student/authentication")
public class StuAuthenticationController {

    @Autowired
    SchoolsService schoolsService;

    @Autowired
    WxAuthenticatedIdentityApplysService wxAuthenticatedIdentityApplysService;

    /**
     * 获取学校列表
     * @return 数据
     */
    @GetMapping("/getAllSchoolList")
    public Result<List<AllSchoolVo>> getAllSchoolList(){
        return schoolsService.getAllSchoolList();
    }

    /**
     * 匹配人脸和身份证号
     * @param matchFacePo 数据
     * @return 反馈
     */
    @PostMapping("/matchFaceAndIdCard")
    public Result<String> matchFaceAndIdCard(@RequestBody(required = false)MatchFacePo matchFacePo){

        if (matchFacePo == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return wxAuthenticatedIdentityApplysService.matchFaceAndIdCard(matchFacePo);
    }

    /**
     * 继续认证
     * @param authPo 数据
     * @return 反馈
     */
    @PostMapping("/completeAuthentication")
    public Result<String> completeAuthentication(@RequestBody(required = false)AuthPo authPo){
        if (authPo == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }


        return wxAuthenticatedIdentityApplysService.completeAuthentication(authPo);
    }

    /**
     * 获取认证信息
     * @param id 微信id
     * @return 反馈
     */
    @GetMapping("/getAuthInfo/{id}")
    public Result<AuthVo> getAuthInfo(@PathVariable(value = "id",required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return wxAuthenticatedIdentityApplysService.getAuthInfo(id);
    }
}
